package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

//在JDBC中设置事务的隔离级别
public class Demo12 {
    public static void main(String[] args) {
        try ( Connection con=DBUtil.getConnection();){
            con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);//设置事务的隔离级别
            con.setAutoCommit(false);
            String sql="INSERT INTO user (username,password,nickname,age) "+
                       "VALUAES (?,?,?,?)";
            PreparedStatement pre=con.prepareStatement(sql);
            pre.setString(1,"宝瓶");
            pre.setString(2,"235689");
            pre.setString(3,"女夫子");
            pre.setInt(4,11);
            int num=pre.executeUpdate();
            System.out.println(num>0?"插入成功":"插入失败");
            con.commit();
        } catch (SQLException e) {
           // con.rollBack();
            e.printStackTrace();
        }
    }
}
